/**
 * @author hoang.pt
 * @version $Id: Thread3.java 175 2010-09-10 03:50:49Z phantichhoang $
 */

package test1.problem2;


/**
 *
 * @author hoang.pt
 */
public class Thread3  implements Runnable{

    Thread t;

    Data d;

    /**
     * constructor
     */
    public Thread3(Data d) {

        //init data
        this.d = d;

        //init thread
        t = new Thread(this);
        t.start();
    }

    
    /**
     * 
     */
    public void run()
    {
        //run forever
        while (true) {

            //synchronise
            synchronized(d) {
                
                //check flag
                //if false get random
                if (!d.flag) {
                    //--get random
                    d.getRandom();

                    //--change flag
                    d.flag = true;
                }
            }
        }
    }
}
